﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BookingManagementSystem.Models;


namespace BookingManagementSystem.Controllers
{
    public class BookingsController : Controller
    {
        //
        // GET: /Bookings/

        public ActionResult Index()
        {
            var bookings = DataAccessLayer.GetAllBookings();
            return View(bookings);
        }

        public void DeleteBooking(int idBooking)
        {
            DataAccessLayer.DeleteBooking(idBooking);
        }

        [HttpGet]
        public ActionResult EditPartialBookingById(int idBooking)
        {
            var booking = DataAccessLayer.GetBookingById(idBooking);
            booking.AllCustomers = DataAccessLayer.GetAllCustomers();
            booking.AllOrigins = DataAccessLayer.GetAllOrigins();
            booking.AllRooms = DataAccessLayer.GetAllRooms();
            return PartialView("ViewUserControlBookingParcial", booking);
        }

        [HttpPost]
        public void EditPartialBookingById(BookingModel booking)
        {
            DataAccessLayer.EditBooking(booking);
        }

        [HttpGet]
        public ActionResult CreatePartialBooking(int startDateSecs)
        {
            DateTime startDate = Tools.UnixTimeStampToDateTime(startDateSecs);
            BookingModel newBooking = new BookingModel(DataAccessLayer.GetAllCustomers(), DataAccessLayer.GetAllRooms(), DataAccessLayer.GetAllOrigins());
            newBooking.CheckInDate = startDate;
            newBooking.CheckOutDate = startDate.AddHours(1);
            return PartialView("ViewUserControlBookingParcial", newBooking);
        }

        [HttpPost]
        public void CreatePartialBooking(BookingModel booking)
        {
            DataAccessLayer.AddBooking(booking);
        }
    }
}
